<?php
/*********************/
/*                   */
/*  后台文章控制       */
/*   BY voiet        */
/*   2009-7-30       */
/*                   */
/*********************/

//require_once( CORE_DIR."/admin/controller/content/ctl.articles.php" );
class cct_articles extends ctl_articles
{
	
	
	function addnew( $node_id )
	{
		$this->path[] = array( "text" => "添加文章" );
		$sitemap = $this->system->loadmodel( "content/sitemap" );
		$this->pagedata['node_id'] = $node_id;
		$oArticle = $this->system->loadmodel( "content/article" );
		$this->pagedata['article_cat'] = $oArticle->getarticlecat( );
		
		$oMember = $this->system->loadmodel( "member/member" );
		$aMemberLevelList = $oMember->getlevellist( false );
		foreach ( $aMemberLevelList as $k => $v )
		{
			$aTmpMList[$v['member_lv_id']] = $v['name'];
		}
		$this->pagedata['mLev'] = $aTmpMList;
		
		$this->page( "content/article/article.html" );
	}
	
	function detail( $nConId )
	{
		$oArticle = $this->system->loadmodel( "content/article" );
		$sitemap = $this->system->loadmodel( "content/sitemap" );
		
		$this->pagedata['article'] = $oArticle->get( $nConId );
		$this->pagedata['node_id'] = $this->pagedata['article']['node_id'];
		$this->pagedata['article_cat'] = $oArticle->getarticlecat( );
		$this->pagedata['article_id'] = $nConId;
		if($this->pagedata['article']['endtime'])
		$this->pagedata['article']['endtime'] = dateformat( $this->pagedata['article']['endtime'] );
		if($this->pagedata['article']['starttime'])
		$this->pagedata['article']['starttime'] = dateformat( $this->pagedata['article']['starttime'] );
		$oMember = $this->system->loadmodel( "member/member" );
		$aMemberLevelList = $oMember->getlevellist( false );
		foreach ( $aMemberLevelList as $k => $v )
		{
			$aTmpMList[$v['member_lv_id']] = $v['name'];
		}
		$this->pagedata['mLev'] = $aTmpMList;
		$this->pagedata['article']['mLev'] = explode( ",", $this->pagedata['article']['limit_level'] );
		$this->setview( "content/article/article.html" );
		$this->output( );
	}
	
	
	function edit( $article_id, $node_id )
	{
		$this->path[] = array( "text" => "编辑文章" );
		$sitemap = $this->system->loadmodel( "content/sitemap" );
		$this->pagedata['node_id'] = $node_id;
		$this->pagedata['path'] = $sitemap->getpathbyid( $node_id, false );
		$oArticle = $this->system->loadmodel( "content/article" );
		$this->pagedata['article'] = $oArticle->get( $article_id );
		$oArticle = $this->system->loadmodel( "content/article" );
		
		$oMember = $this->system->loadmodel( "member/member" );
		$aMemberLevelList = $oMember->getlevellist( false );
		foreach ( $aMemberLevelList as $k => $v )
		{
			$aTmpMList[$v['member_lv_id']] = $v['name'];
		}
		$this->pagedata['mLev'] = $aTmpMList;
		$this->pagedata['article']['mLev'] = explode( ",", $this->pagedata['article']['limit_level'] );
		$this->page( "content/article/article.html" );
	}
	
	
	function addarticle( $node_id )
	{
		if ( $_POST['ifpub'] )
		{
			$GLOBALS['_POST']['ifpub'] = 1;
		}
		else
		{
			$GLOBALS['_POST']['ifpub'] = 0;
		}
		if ( $_POST['ifred'] )
		{
			$GLOBALS['_POST']['ifred'] = 1;
		}
		else
		{
			$GLOBALS['_POST']['ifred'] = 0;
		}
		if ( $_POST['ifevent'] )
		{
			$GLOBALS['_POST']['ifevent'] = 1;
		}
		else
		{
			$GLOBALS['_POST']['ifevent'] = 0;
		}
		if ( $_POST['ifcomment'] )
		{
			$GLOBALS['_POST']['ifcomment'] = 1;
		}
		else
		{
			$GLOBALS['_POST']['ifcomment'] = 0;
		}
		$this->begin( "index.php?ctl=content/articles&act=index" );
		$oArticle = $this->system->loadmodel( "content/article" );
		$this->end( $oArticle->savearticle( $_POST ), __( "文章添加成功" ) );
	}
	
	function save( $article_id, $node_id )
	{
		if ( $_POST['ifpub'] )
		{
			$GLOBALS['_POST']['ifpub'] = 1;
		}
		else
		{
			$GLOBALS['_POST']['ifpub'] = 0;
		}
		if ( $_POST['ifred'] )
		{
			$GLOBALS['_POST']['ifred'] = 1;
		}
		else
		{
			$GLOBALS['_POST']['ifred'] = 0;
		}
		if ( $_POST['ifevent'] )
		{
			$GLOBALS['_POST']['ifevent'] = 1;
		}
		else
		{
			$GLOBALS['_POST']['ifevent'] = 0;
		}
		if ( $_POST['ifcomment'] )
		{
			$GLOBALS['_POST']['ifcomment'] = 1;
		}
		else
		{
			$GLOBALS['_POST']['ifcomment'] = 0;
		}
		$this->begin( "index.php?ctl=content/articles&act=detail&p[0]=".$article_id );
		$oArticle = $this->system->loadmodel( "content/article" );
		$this->end( $oArticle->savearticle( $_POST ), __( "文章保存成功" ) );
	}
	

}

?>